import ChapterStrcut from "../Structs/ChapterStruct";
import G from "../Utilities/Global";

/**
 * 关卡章节ui配置
 * created by Five on 2018-12-21 11:12:46
 */

export default class ChapterConfig {
    public Assets: Map<Number, ChapterStrcut>;
    public AssetsArr: Array<ChapterStrcut>;

    constructor() {
        this.Assets = new Map<Number, ChapterStrcut>();
        this.AssetsArr = new Array<ChapterStrcut>();
        this.init();
    }

    private async init() {
        let asset = await G().Res.LoadFile("config/tables", "ChapterConfig") as cc.JsonAsset;
        let array = asset.json as Array<any>;
        array.forEach(struct => {
            // 外部使用时,注意实例化
            let mas = struct as ChapterStrcut
            this.Assets.set(mas.id, mas);
            this.AssetsArr.push(mas);
        })
        cc.log(this.Assets)
    }

    public GetChapter(index: number) {
        return this.AssetsArr[index - 1];
    }

    public Count(){
        return this.AssetsArr.length;
    }
}